import { observable, action, autorun,toJS,computed } from 'mobx';
import {WeaTools} from "ecCom"
import objectAssign from 'object-assign';
import {message,Modal} from 'antd';
const confirm = Modal.confirm;
import isEqual from 'lodash/isEqual';
import {WeaTableNew,WeaForm} from 'comsMobx'
const {TableStore} = WeaTableNew;
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import * as  Apis from '../../apis/task';
import * as  Apis_prj from '../../apis/project';
import {getFormInitDatas,cptAddFormRules} from "../../util/index"

import {ShareStore } from '../shareStore'
import {ExchangeStore } from "../exchangeStore"
import {TaskInfoStore} from './taskInfoStore'

class TaskCardStore {
    @observable tabDatas = [];
    @observable selectTabKey = "1"
	@observable form = new WeaForm();
    @observable taskInfo= [] ;  //任务信息
	@observable fieldinfo = [] ;  //任务信息

    @observable loading = false;
	@observable taskid ="";
	@observable targetid ="";
	discusstype = "PT";

	@observable prjid ="";
	taskname="";
	validateRules = {};

    @observable showSearchAd = false  // 高级搜索显示
    @observable taskSubStore = new TableStore();
    @observable tasksubform  = new WeaForm();
    @observable rightMenu = [];
	@observable condition = [];
	
	@observable shareStore = new ShareStore();
	@observable exchangeStore = new ExchangeStore();
	@observable taskInfoStore = new TaskInfoStore();

	@observable taskLogTableStore = new TableStore();  //日志

	@observable taskFieldLogTableStore = new TableStore();  //字段日志

	@observable taskFieldDetailLogTableStore = new TableStore();  //字段详情日志

	@observable fieldLogVisible = false;

	@observable fieldDetailLogVisible = false;

	@observable fieldname = '';

	@observable field = '';

	@observable shareTableStore =  new TableStore();
	@observable isShowShare = false;
	@observable shareRight={
		hasRight:false,
		verified:false
	}

	@observable isNow = true;
	@observable isTimeShow = true;

	@observable canSave = true;

	shareCondition = [
		{
			"colSpan": 2,
			"conditionType": "SELECT",
			"domkey": [
				"sharetype"
			],
			"fieldcol": 18,
			"isQuickSearch": false,
			"label": getLabel(21956,"对象类型"),
			"labelcol": 6,
			"options": [
				{
					"key": "1",
					"selected": true,
					"showname": getLabel(179,"人力资源")
				}, {
					"key": "5",
					"selected": false,
					"showname": getLabel(141,"分部")
				}, {
					"key": "2",
					"selected": false,
					"showname": getLabel(124,"部门")
				}, {
					"key": "11",
					"selected": false,
					"showname": getLabel(6086,"岗位")
				}, {
					"key": "3",
					"selected": false,
					"showname": getLabel(122,"角色")
				}, {
					"key": "4",
					"selected": false,
					"showname": getLabel(1340,"所有人")
				}
			],
			"viewAttr": 2
		}, {
			"2": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": false,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "57",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "INPUT_INTERVAL",
						"needDefaultValue":false,
						"domkey": [
							"seclevel",
							"seclevelMax"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(683,"安全级别"),
						"labelcol": 6,
						"value": [
							0,
							''
						],
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"5": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": false,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "194",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"value": 3,
						"viewAttr": 2
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "INPUT_INTERVAL",
						"needDefaultValue":false,
						"domkey": [
							"seclevel",
							"seclevelMax"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(683,"安全级别"),
						"labelcol": 6,
						"value": [
							0,
							''
						],
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"1": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": false,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "17",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"11": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": false,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "278",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT_LINKAGE",
						"domkey": [
							"joblevel"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(28169,"岗位级别"),
						"labelcol": 6,
						"options": [
							{
								"key": "0",
								"selected": true,
								"showname": getLabel(140,"总部")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(19437,"指定分部")
							}, {
								"key": "1",
								"selected": false,
								"showname": getLabel(19438,"指定部门")
							}
						],
						"selectLinkageDatas": {
							"1": {
								"browserConditionParam": {
									"completeParams": {},
									"conditionDataParams": {},
									"dataParams": {},
									"destDataParams": {},
									"hasAddBtn": false,
									"hasAdvanceSerach": true,
									"idSeparator": ",",
									"isAutoComplete": 1,
									"isDetail": 0,
									"isMultCheckbox": false,
									"isSingle": false,
									"pageSize": 10,
									"quickSearchName": "",
									"type": "57",
									"viewAttr": 3
								},
								"colSpan": 2,
								"conditionType": "BROWSER",
								"domkey": [
									"jobtitledepartment"
								],
								"fieldcol": 18,
								"isQuickSearch": false,
								"label": "",
								"labelcol": 6,
								"viewAttr": 3
							},
							"2": {
								"browserConditionParam": {
									"completeParams": {},
									"conditionDataParams": {},
									"dataParams": {},
									"destDataParams": {},
									"hasAddBtn": false,
									"hasAdvanceSerach": true,
									"idSeparator": ",",
									"isAutoComplete": 1,
									"isDetail": 0,
									"isMultCheckbox": false,
									"isSingle": false,
									"pageSize": 10,
									"quickSearchName": "",
									"type": "194",
									"viewAttr": 3
								},
								"colSpan": 2,
								"conditionType": "BROWSER",
								"domkey": [
									"jobtitlesubcompany"
								],
								"fieldcol": 18,
								"isQuickSearch": false,
								"label": "",
								"labelcol": 6,
								"viewAttr": 3
							}
						},
						"viewAttr": 2
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"4": [[
					{
						"colSpan": 2,
						"conditionType": "INPUT_INTERVAL",
						"needDefaultValue":false,
						"domkey": [
							"seclevel",
							"seclevelMax"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(683,"安全级别"),
						"labelcol": 6,
						"value": [
							0,
							''
						],
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"3": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": false,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "65",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"viewAttr": 3
					}, {
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"rolelevel"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(139,"级别"),
						"labelcol": 6,
						"options": [
							{
								"key": "0",
								"selected": true,
								"showname": getLabel(124,"部门")
							}, {
								"key": "1",
								"selected": false,
								"showname": getLabel(141,"分部")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(140,"总部")
							}
						],
						"viewAttr": 2
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "INPUT_INTERVAL",
						"needDefaultValue":false,
						"domkey": [
							"seclevel",
							"seclevelMax"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(683,"安全级别"),
						"labelcol": 6,
						"value": [
							0,
							''
						],
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 18,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			]
		}
	]

	@observable taskReqStore =  new TableStore(); //流程
	@observable taskDocStore = new TableStore();  //文档
	@observable taskCrmStore = new TableStore();  //客户
	@observable taskCptStore = new TableStore();   //资产
	@observable taskRelRight={
		hasRight:false,
		verified:false
	}
	@observable crmType="add";
	@observable crmVisible = false;
	@observable crmUpdateid="";
	@observable relateCrmform = new WeaForm();

	@observable logVisible =false;   //任务修改记录
	@observable logTableStore = new TableStore();

	@observable relateList ={} ; // 查询结果集

	@observable exchangeList = "";
	@observable _BrowserList = {
		'create': {remark: ''},
		datas: [],
	};

	@observable verified = false;
	@observable hasRight = false; //权限
	 
	@action 
	reLoad = (tableStore) => {
        tableStore.getDatas(tableStore.dataKey, tableStore.current,tableStore.pageSize,tableStore.sortParams)
	}

	
	getTaskTabs = (params = {}) => {
		params.isNow = this.isNow;
		this.taskid = params.taskid;
		this.prjisdel = false;
		Apis.getTaskTabs(params).then(data => {
			if (!data.isright && typeof (data.isright) !== "undefined") {
				this.hasRight = data.isright;
				this.verified = true;
			} else {
				this.hasRight = true;
				this.verified = true;
				this.tabDatas = data.tabs;
				this.changeTab(this.selectTabKey);
			}
		})
	}

	
    @action 
    //设置选中按钮
    changeTab=(key)=>{
	   this.selectTabKey = key;
	   this.rightMenu = [];
	//    if(key == 'taskinfo'){
	// 		this.getTaskForm({viewtype:'view',taskid:this.taskid});
	//    }else if(key == "tasksub"){
	// 		this.condition=[];
    //         this.getTaskSubList();
    //         Apis.getTaskSubCondition({conditiontype:'tasksub'}).then(data=>{
    //             this.condition = data.condition;
    //             this.tasksubform && !this.tasksubform.isFormInit && this.tasksubform.initFormFields(data.condition);
    //         });
    //    } else if(key == "taskshare"){
    //         this.getTaskShareList();
	//    }else if(key == "req" || key == "doc" ||key == "crm" ||key == "cpt"){
	// 		this.getTaskReference(key);
	// 		this.taskRelRight={
	// 			hasRight:false,
	// 			verified:false
	// 		}
	// 	}else if(key == "exchange"){
	// 		this.targetid = this.taskid;
	// 		this.getExchangeList({});
	// 	}
		
		const tabDatas = toJS(this.tabDatas);
		if (tabDatas) {
			for (let i = 0; i < tabDatas.length; i++) {
				if (tabDatas[i].id == key && tabDatas[i].shortname == "taskinfo") {   //基本信息
					this.getTaskForm({viewtype:'view',taskid:this.taskid,isNow:this.isNow});
				} else if (tabDatas[i].id == key && tabDatas[i].shortname == "tasksub") {//任务列表
					this.condition=[];
					this.getTaskSubList();
					Apis.getTaskSubCondition({conditiontype:'tasksub'}).then(data=>{
						this.condition = data.condition;
						this.tasksubform && !this.tasksubform.isFormInit && this.tasksubform.initFormFields(data.condition);
					});
				} else if (tabDatas[i].id == key && tabDatas[i].shortname == "taskshare") { //子项目
					this.getTaskShareList();
				} else if (tabDatas[i].id == key && (tabDatas[i].shortname == "req" || tabDatas[i].shortname == "doc"  || tabDatas[i].shortname == "crm"  || tabDatas[i].shortname == "cpt" )) {  //相关交流
					this.getTaskReference(tabDatas[i].shortname);
					this.taskRelRight={
						hasRight:false,
						verified:false
					}
				} else if (tabDatas[i].id == key && tabDatas[i].shortname == "exchange") {  //共享设置
					this.targetid = this.taskid;
					this.getExchangeList({});
				} 
			}
		}
    }
	//任务信息
    getTaskForm=(params={})=>{
		this.loading = true;
		this.form = new WeaForm();
        Apis.getTaskForm(params).then(data=>{
			if(!data.isright && typeof(data.isright) !== "undefined"){
				this.hasRight = data.isright;
				this.verified = true;
			}else{
				this.isTimeShow = data.isTimeShow;
				this.hasRight = true;
				this.verified = true;
				this.taskid = data.taskid ||params.taskid ;
				this.prjid = data.prjid;
				this.taskname = data.taskname;
				this.taskInfo = data;
				this.fieldinfo = data.fieldinfo;
				this.rightMenu = data.rightMenus;
				this.loading = false;
				this.form && !this.form.isFormInit && this.form.initFormFields(this.fieldinfo);
				this.form.isFormInit && this.form.updateFields(getFormInitDatas(this.fieldinfo),false);
			};
			
        })
	}
	//任务信息保存
	saveTaskInfo=(params={})=>{
		this.form.validateForm().then(f=>{
            if(f.isValid){
				let newParams = {method:'edit',...toJS(this.form.getFormParams()),taskid:this.taskid,...params};
				Apis.saveTaskInfo(newParams).then(data=>{
					window.opener&&window.opener._table&&window.opener._table.reLoad();
					this.getTaskForm({viewtype:'view',taskid:this.taskid});
					this.canSave = true;
				})
            }else{
                f.showErrors();
            }
        });
	}
	//任务删除
	@action
    delTask=(type,taskid)=>{
        let _this = this;
        Modal.confirm({
            title: getLabel(15172,"系统提示"),
            content: getLabel(83925,"该任务及其子任务都会被删除，您确认要删除吗？"),
            onOk() {
                Apis.delTask({method:type,taskid:taskid}).then(data=>{
                    if(data.success){
						window.opener&&window.opener._table&&window.opener._table.reLoad();
						window.close();
                    }else{
                        message.error(getLabel(383746,"请求失败")+"："+data.msgcode);
                    }
                })
            },
            onCancel() { },
        })
	}
	
    //子任务列表
    getTaskSubList=(params={})=>{
         //获取表单的参数值
         this.loading = true;
		 const searchParamsAd = this.tasksubform.getFormParams();
		 const newParams = { taskid:this.taskid, ...searchParamsAd, ...params };
        Apis.getTaskSubList(newParams).then(data=>{
            this.taskSubStore.getDatas(data.sessionkey,  1);
            this.rightMenu = data.rightMenus;
            this.loading = false;
        });
	}
	
	//添加共享v
	addShare = (value)=>{
		Apis.addTaskShare({...value,method:'add',taskid:this.taskid,opttype:'task'}).then(data=>{
			this.getTaskShareList();
		})
	}
	//批量删除
	delBatchShare = (value)=>{
		let _this = this;
        Modal.confirm({
            title: getLabel(15172,"系统提示"),
            content: getLabel(83601,"您确认要删除选中的记录吗？"),
            onOk() {
                Apis.delBatchTaskShare({id:value,method:'batchdelete',opttype:'task'}).then(data=>{
					_this.getTaskShareList();
				});
            },
            onCancel() { },
		})
	}

    //高级搜索设值
    setFormFields=(value)=>{
		const tabDatas = toJS(this.tabDatas);
		if (tabDatas) {
			for (let i = 0; i < tabDatas.length; i++) {
				if (tabDatas[i].id == this.selectTabKey && tabDatas[i].shortname == "taskinfo") {   //基本信息
					this.form.updateFields(value, false);    //true代表完全覆盖方式更新条件值
				}
				if (tabDatas[i].id == this.selectTabKey && tabDatas[i].shortname == "tasksub") {   //基本信息
					this.tasksubform.updateFields(value, false);    //true代表完全覆盖方式更新条件值
				}
				if (tabDatas[i].id == this.selectTabKey && tabDatas[i].shortname == "exchange") {   //基本信息
					this.exchangeform.updateFields(value, false);    //true代表完全覆盖方式更新条件值
				}
			}
		}
    }
    //共享
    getTaskShareList=(params={})=>{
        //获取表单的参数值
        this.loading = true;
        const newParams = { taskid:this.taskid, ...params };
       Apis.getTaskShareList(newParams).then(data=>{
			if(!data.isright && typeof(data.isright) !== "undefined"){
				this.shareRight = {
					hasRight:data.isright,
					verified:true
				};
			}else{
				this.shareRight = {
					hasRight:true,
					verified:true
				};
				this.shareTableStore.getDatas(data.sessionkey,  1);
				this.rightMenu = data.rightMenus;
			}
			this.loading = false;
       });
	}
	showAddShareModal=(bool)=>{
		this.isShowShare = bool;
	}
	//相关流程-文档-资产-客户
	getTaskReference=(type)=>{
		this.loading = true;
		const newParams = { taskid:this.taskid, reftype:type};
		Apis.getTaskReference(newParams).then(data=>{
			if(!data.isright && typeof(data.isright) !== "undefined"){
				this.taskRelRight = {
					hasRight:data.isright,
					verified:true
				};
			}else{
				this.taskRelRight = {
					hasRight:true,
					verified:true
				};
				if(type== "req"){
					this.taskReqStore.getDatas(data.sessionkey,1);
					this.relateList = data;
					this.rightMenu = data.rightMenus;
				}else if(type== "doc"){
					this.taskDocStore.getDatas(data.sessionkey,1);
					this.relateList = data;
					this.rightMenu = data.rightMenus;
				}else if(type == "crm"){
					this.taskCrmStore.getDatas(data.sessionkey,1);
					this.rightMenu = data.rightMenus;
				}else if(type == "cpt"){
					this.taskCptStore.getDatas(data.sessionkey,1);
					this.rightMenu = data.rightMenus;
				}
			}
			this.loading = false;
		});

	}
		//所需流程文档操作
	doDspTaskRequiredOpt = (params={},type) =>{
		Apis.doDspTaskRequiredOpt(params).then(data=>{
			this.getTaskReference(type);
			if(params.method == "addRequiredWF" || params.method == "addRequiredDoc"){
				message.success(getLabel(83880,"添加成功！"));
			}else if(params.method == "delRequiredWF" || params.method == "delRequiredDoc"){
				message.success(getLabel(83472,"删除成功！"));
			}
		})
	}
	//相关流程文档操作
	doDspTaskReferenceOpt = (params={},type)=>{
		Apis.doDspTaskReferenceOpt(params).then(data=>{
			this.getTaskReference(type);
			message.success(params.method =="del" ? getLabel(83472,"删除成功！"):getLabel(83880,"添加成功！"));
		})
	}
	//修改相关客户，设置修改id
	setRelateCrmUpdateID = (id)=>{
		this.crmUpdateid = id;
	}

	//添加相关客户
	saveRelateCrm = ()=>{
		this.relateCrmform.validateForm().then(f=>{
            if(f.isValid){
				this.handleRelateCrmDialog(false,this.crmType);
				this.doDspTaskReferenceOpt({
					dotype:'crm',
					method :this.crmType,
					prjid:this.prjid,
					taskid:this.taskid,
					id:this.crmUpdateid,
					...this.relateCrmform.getFormParams()
				},"crm")
            }else{
                f.showErrors();
            }
        });
	}

	//删除
	exchangeDelete = (value) => {
		let _this = this;
		Apis_prj.exchangeDelete(value).then(data => {
			if(data.status){
				_this.getExchangeList()
			}else {
				message.error(data.error ? data.error : `${getLabel(384137,'操作失败！')}`);
			}
		})
	}

	//获取相关交流信息
	@action
	getExchangeList = (value) => {
		let _this = this;
		const newParams = { types: "PT", sortid: this.taskid, ...value };
		Apis_prj.getExchangeList(newParams).then(data => {
			let exchange = { ...data }
			exchange.datas.forEach((element, index) => {
				element.isEdit = false
			})
			exchange.datas.unshift({
				id: 'create',
				isEdit: true,
				remark: '',
				docids: [],
				projectids: [],
				relatedcus: [],
				relateddoc: [],
				relatedprj: [],
				relatedwf: [],
			})
			_this.exchangeList = exchange;
			_this._BrowserList = {
				'create': {remark: ''},
				datas: [],
			};
			_this.exchangeList.datas&&_this.exchangeList.datas.forEach((element, index) => {
				if (_this._BrowserList[element['id']] == undefined) {
					_this._BrowserList[element['id']] = {};
				}
				_this._BrowserList[element['id']].remark = element.remark;
				_this._BrowserList[element['id']].docids = element.docids;
				_this._BrowserList[element['id']].projectids = element.projectids;
				_this._BrowserList[element['id']].relatedcus = element.relatedcus;
				_this._BrowserList[element['id']].relateddoc = element.relateddoc;
				_this._BrowserList[element['id']].relatedprj = element.relatedprj;
				_this._BrowserList[element['id']].relatedwf = element.relatedwf;
			})
			_this._BrowserList.datas = _this.exchangeList.datas;
		})
	}

	//相关交流datas循环
	changeDiscussList = (value = {}) => {
		this.exchangeList = value;
		this.exchangeList.datas&&this.exchangeList.datas.forEach((element, index) => {
			if (this._BrowserList[element['id']] == undefined) {
				this._BrowserList[element['id']] = {};
			}
			this._BrowserList[element['id']].remark = element.remark;
			this._BrowserList[element['id']].docids = element.docids;
			this._BrowserList[element['id']].projectids = element.projectids;
			this._BrowserList[element['id']].relatedcus = element.relatedcus;
			this._BrowserList[element['id']].relateddoc = element.relateddoc;
			this._BrowserList[element['id']].relatedprj = element.relatedprj;
			this._BrowserList[element['id']].relatedwf = element.relatedwf;
		})
		this._BrowserList.datas = this.exchangeList.datas;
	}

	//相关交流提交
	exchangeSave = (value) => {
		let _this = this;
		Apis_prj.exchangeSave({...value,discusstype:'PT'}).then(data => {
			if(data.status){
				_this.getExchangeList({ });
			}else {
				message.error(data.error ? data.error : `${getLabel(384137,'操作失败！')}`);
			}
		})
	}

	//相关交流提交
	setBrowserList = (_BrowserList) => {
		this._BrowserList = _BrowserList;
	}
		//form 重置
    clearFormFields=()=>{
		const tabDatas = toJS(this.tabDatas);
		if (tabDatas) {
			for (let i = 0; i < tabDatas.length; i++) {
				if (tabDatas[i].id == this.selectTabKey && tabDatas[i].shortname == "tasksub") {  
					this.tasksubform.reset();      //清除查询条件值
				} else if (tabDatas[i].id == this.selectTabKey && tabDatas[i].shortname == "exchange") {  
					this.exchangeform.reset();      //清除查询条件值
				}
			}
		}
    }
    //高级搜索显隐
    setShowSearchAd=(bool)=>{
        this.showSearchAd = bool
    }
    onShowColumn=()=>{   //显示定制列
        const tabDatas = toJS(this.tabDatas);
		if (tabDatas) {
			for (let i = 0; i < tabDatas.length; i++) {
				if (tabDatas[i].id == this.selectTabKey && tabDatas[i].shortname == "tasksub") {  
					this.taskSubStore.setColSetVisible(true);
					this.taskSubStore.tableColSet(true)
				}
			}
		}
	}
	//保存规则
	setValidate=(params={})=>{
		this.validateRules = params;
	}
	//操作相关客户
	handleRelateCrmDialog = (bool,type,value)=>{
		this.crmVisible = bool;
		this.crmType = type;
		this.relateCrmform.updateFields(value,false);
		
	} 
	//修改记录
	viewModifyLog = (id)=>{
		this.logVisible = true;
		this.logTableStore = new TableStore();
		Apis.taskModifyList({taskid:id}).then(data=>{
			this.logTableStore.getDatas(data.sessionkey,1);
		})
	}

	saveAndReLoadWf = (params) => {
		Apis.addRequiredWF({...params,taskid:this.taskid,prjid:this.prjid}).then(data=>{
			if(data.status){
				this.getTaskReference("req");
				message.success(getLabel(83880,"添加成功！"));
			}else{
				message.error(data.error ? data.error : `${getLabel(384137,'操作失败！')}`);
			}
		})
	}

	@computed
	get register_table() {
		return {
			reLoad: (param) => {
				if(param.requestid && param.requestid == -1){
					this.saveAndReLoadWf(param)
				}
			}
		};
	}

	getTaskLogList = (params = {}) => {
		Apis.getTaskLogList(params).then(data => {
			this.taskLogTableStore.getDatas(data.sessionkey, 1);
		})
	}

	getPrjFieldLogList = (params = {}) => {
		Apis.getTaskFieldLogList({taskid:this.taskid,...params}).then(data => {
			this.taskFieldLogTableStore.getDatas(data.sessionkey, 1);
		})
	}

	getPrjFieldDetaiLogList = (params = {}) => {
		Apis.getTaskFieldDetailLogList({taskid:this.taskid,...params}).then(data => {
			this.taskFieldDetailLogTableStore.getDatas(data.sessionkey, 1);
		})
	}

	@action
	setFieldLogVisible = (v) =>{
		this.fieldLogVisible = v;
	}

	@action
	setFieldDetailLogVisible = (v) =>{
		this.fieldDetailLogVisible = v;
	}

	@action
	setFieldName = (v) =>{
		this.fieldname = v;
	}

	@action
	setField = (v) =>{
		this.field = v;
	}

	@action
	setIsNow = (v)=>{
		this.isNow = v;
	}

	@action
	setCanSave = (v) =>{
		this.canSave = v;
	}

}
const taskCardStore = new TaskCardStore()
export default taskCardStore;